<?php
/**
 * This file is part of the Yacms (http://www.yacms.org)
 * Copyright (c) 2019 gylr0505 (http://www.yacms.org)
 *
 * Author: 鬼一浪人 <gylr0505@163.com>
 *
 * DateTime: 19-10-25 上午12:30
 * Description:
 */
 
declare(strict_types = 1);

namespace App\Template;

use App\Model\Entity\FormId;
use Carbon\Carbon;

class TemplateService
{
    public static function getFirstFromIdByOpenId($open_id)
    {
        $now = Carbon::now();
        $now->subDays(7);

        return FormId::query()->select('form_id')
            ->where([
                'open_id' => $open_id
            ])
            ->where([
                ['created_at' ,'>=', $now]
            ])
            ->value('form_id');
    }

    /**
     * @param $form_id
     * @throws \ReflectionException
     * @throws \Swoft\Bean\Exception\ContainerException
     * @throws \Swoft\Db\Exception\DbException
     */
    public static function deleteByFormId($form_id)
    {
        if (!$form_id){
            return;
        }
        FormId::query()->where(['form_id' => $form_id])->delete();
    }
}